package com.sk.sqd.defaultImpl;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component {

    // 存储下级节点
    private List<Component> childList = new ArrayList<>();

    @Override
    public void add(Component component) {
        childList.add(component);
    }

    @Override
    public void remove(Component component) {
        childList.remove(component);
    }

    @Override
    public void display() {
        System.out.println(name);
        childList.forEach(Component::display);
    }

    public Composite(String name) {
        this.name = name;
    }
}
